﻿/*==============================================================
 * NavExtensions.cs
 * Copyright (C) 2014 贵州惠众互联 Inc. All rights reserved.
 *==============================================================
 * Author:   罗应红
 * Date:     2014/03/04 16:20:14.
 * Version:  1.0
 * QQ:		 88962800
*==============================================================*/

using System.Collections.Generic;
using System.Linq;
using QDT.Core.Domain;
using QDT.Web.Admin.Models;

namespace QDT.Web.Admin.Helper {
    public static class NavExtensions {
        public static IList<NavModel> ToModelList(this IList<MenuNav> entities) {
            var result = new List<NavModel>();
            if (entities == null || entities.Any()) {
                return result;
            }
            result = entities.Select(ToModel).ToList();
            return result;
        }

        public static NavModel ToModel(this MenuNav entity) {
            return new NavModel {
                IsEffect = entity.IsEffect,
                Id = entity.ID,
                Sort = entity.Sort,
                Child = entity.Child.ToModelList(),
                ParentId = entity.ParentId,
                Name = entity.Name,
                AppIndex = entity.AppIndex,
                IsBlank = entity.IsBlank,
                IsShop = entity.IsShop,
                UAction = entity.UAction,
                UId = entity.UId,
                UModule = entity.UModule,
                UParam = entity.UParam,
                Url = entity.Url
            };
        }

        public static MenuNav ToEntity(this NavModel model) {
            return new MenuNav {
                IsEffect = model.IsEffect,
                Sort = model.Sort,
                Child = null,
                ID = model.Id,
                ParentId = model.ParentId,
                Name = model.Name,
                AppIndex = model.AppIndex,
                IsBlank = model.IsBlank,
                IsShop = model.IsShop,
                Parent = null,
                UModule = model.UModule,
                UAction = model.UAction,
                UId = model.UId,
                UParam = model.UParam,
                Url = model.Url
            };
        }
    }
}